package com.fourthGroup.fallback;

import com.fourthGroup.feign.UserClient;
import com.fourthGroup.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {
    
    @Override
    public UserClient create(Throwable cause) {
        return new UserClient() {
            @Override
            public User queryUserById(Integer uid) {
                log.error("查询用户服务调用失败，用户ID: {}, 错误原因: {}", uid, cause.getMessage());
                User fallbackUser = new User();
                fallbackUser.setUid(-1);
                fallbackUser.setUsername("用户服务暂时不可用");
                return fallbackUser;
            }
        };
    }
} 